import 'package:flutter/material.dart';
import 'package:route_manager/route_bridge.dart';
import 'package:wallet_authentication/mnemonic/pages/recover_mnemonic_page.dart';
import 'PIN/models/wallet_info_model.dart';
import 'module_config.dart';
import 'PIN/pages/PIN_setting_page.dart';
import 'PIN/pages/check_PIN_page.dart';
import 'PIN/pages/create_wallet_page.dart';
// import 'address_book/pages/address_book_page.dart';
// import 'address_book/pages/address_new_page.dart';
import 'mnemonic/pages/backup_mnemonic_page.dart';
import 'mnemonic/pages/verify_mnemonic_page.dart';
import 'start/pages/wallet_start_page.dart';

class ModuleWalletAuthentication extends WXModuleRoute {
  @override
  String getModuleName() {
    return ModuleConfig.moduleName;
  }

  @override
  Route onGenerateRoute(settings) {
    switch (settings?.name) {
      case '/WalletStartPage':
        return MaterialPageRoute(
            settings: settings,
            builder: (context) {
              return WalletStartPage();
            });
        break;
      case '/walletCreate':
        // WalletSource arguments = settings.arguments;
        int arguments = settings.arguments;

        return MaterialPageRoute(
            settings: settings,
            builder: (context) {
              return arguments == null
                  ? CreateWalletPage()
                  : CreateWalletPage(
                      walletSource: arguments,
                    );
            });
        break;

      case '/pinSetting':
        // Map<String, dynamic> arguments = {'isUpdate':true, 'walletSource':WalletSource.create};
        Map<String, dynamic> arguments = settings.arguments;
        // isUpdate：设置 ｜ 修改 默认是设置
        bool isUpdate = arguments['isUpdate'];
        // walletSource：创建 ｜ 恢复 默认是创建
        // WalletSource walletSource = arguments['walletSource'];
        int walletSource = arguments['walletSource'];

        return MaterialPageRoute(
            settings: settings,
            builder: (context) {
//              FIXME: 这坨代码是不是可以这样写 return PINSettingPage(isUpdate: isUpdate ?? false,walletSource: walletSource ?? 0);
              if (isUpdate != null && walletSource != null) {
                return PINSettingPage(
                  isUpdate: isUpdate,
                  walletSource: walletSource,
                );
              } else if (isUpdate != null) {
                return PINSettingPage(
                  isUpdate: isUpdate,
                );
              } else if (walletSource != null) {
                return PINSettingPage(
                  walletSource: walletSource,
                );
              } else {
                return PINSettingPage();
              }
            });
        break;

      case '/mnemonicBackup':
        int arguments = settings.arguments;

        return MaterialPageRoute(
            settings: settings,
            builder: (context) {
              return arguments == null
                  ? BackupMnemonicWalletScreen()
                  : BackupMnemonicWalletScreen(showType: arguments);
            });
        break;

      case '/mnemonicVerify':
        String arguments = settings.arguments;

        return MaterialPageRoute(
            settings: settings,
            builder: (context) {
              return VerifyMnemonicWalletScreen(mnemonicString: arguments);
            });
        break;

      case '/mnemonicRecover':
        return MaterialPageRoute(
            settings: settings,
            builder: (context) {
              return RecoverMnemonicPage();
            });
        break;

      case '/checkPINPage':
        // {'callback':void Function(String value), 'isHiddenBack':isHiddenBack}
        Map<String, dynamic> arguments = settings.arguments;

        // void Function(String value) callback = arguments['callback'];
        // bool isHiddenBack = arguments['isHiddenBack'];

        return MaterialPageRoute(
            settings: settings,
            builder: (context) {
              return CheckPINPage(
                settingsMap: arguments,
                // onCallBack: callback,
              );
            });
        break;
      // case '/addressBookPage':
      //   // Map<String, dynamic> arguments = settings.arguments;

      //   return MaterialPageRoute(
      //       settings: settings,
      //       builder: (context) {
      //         return AddressBookPage();
      //       });
      //   break;
      // case '/addressNewPage':
      //   dynamic arguments = settings.arguments;

      //   return MaterialPageRoute(
      //       settings: settings,
      //       builder: (context) {
      //         return AddressNewPage(
      //           addressItem: arguments,
      //         );
      //       });
      //   break;

      default:
        return null;
    }
  }
}
